Core.Storage.Rule = function() {
	this.rules = {};
}

Core.Storage.Rule.prototype = {
	
	__clear: function() {},
	
	/**
	 * Returns path to the closest NotifyPoint available.
	 * @param Array arr
	 */
	getNormalizedPath: function(arr) {
		var rules = this.rules[arr[0]], max = "";
		
		if(rules) {
			var raw = arr.join("."), 
				l = rules.length, i = 0;
			
			for(; i < l; i++) {
				var tmp = raw.match(rules[i]);
				if(tmp && tmp[0].length > max.length) { max = tmp[0]; }
			}
		}
		return max;
	},
	
	/**
	 * Creates specified rule on the given path.
	 * @param String path
	 */
	register: function(raw) {
		Core.assert(Core.App.isLoading(), "Application not in its loading state on StorageRule registering.");
		
		var idx = raw.indexOf("."),
			head = raw.substr(0, (idx > 0 ? idx : undefined));
		
		raw = raw.replace(/\./g, "\\.");
		raw = raw.replace(/\*/g, "[-a-zA-Z0-9_]+");
		raw += "(?![-a-zA-Z0-9_])";
		
		if(!this.rules[head]) { this.rules[head] = []; }
		this.rules[head].push(new RegExp("^" + raw));
	}
};

Core.Storage.Rule = Singleton.register("core.storage.rule", Core.Storage.Rule);